
var app = new Vue({
    el: '#app',
    data: {
        id: 0,
        //搜索
        classify: [
            {id: 0,name: '无雾'},
            {id: 1,name: '轻雾'},
            {id: 2,name: '浓雾'}
        ],
        //内容
        fogFrom:{
            id: 0,
            mid: 0,
            value: 0.0,
            url: "",
            level: 0,
            date: ""
        },
        //图片
        dialogImageUrl: '',
        dialogVisible: false,
        myurl:[]
    },
    mounted() {
        //sessionStorage 是会话存储，关闭浏览器就没了
        this.id=sessionStorage["Fogid"];
        this.fogFrom.id = this.id;
        console.log(this.fogFrom.id)
        if (this.id !== 0){
            this.getFogLevel();
        }
        $(".el-upload--picture-card").css("display","none");
    },
    methods:{
        getFogLevel(){
            const params = {
                id: this.fogFrom.id,
            };
            this.$http.post('/admin/FogLevelOne',params,{emulateJSON:true}).then(res => {
                console.log(res);
                this.fogFrom.mid=res.body.FogLevel.mid;
                this.fogFrom.value=res.body.FogLevel.value;
                this.fogFrom.url=res.body.FogLevel.url;
                this.fogFrom.level=res.body.FogLevel.level;
                this.fogFrom.date=res.body.FogData;
                this.myurl.push({url: res.body.FogLevel.url});
                this.myurl[0].url='http://nitcs.ahalk.cn/img/'+this.myurl[0].url;
                $("div[id*='left_y']").hide();
                $("#" + res.body.left).show();
                $("#" + res.body.show_left).attr("style", "background: #293038;");
                $("#"+res.body.top).attr("style","background: #008fbf;");
                $(".top_admin .list-group").hide();
            });
        },
        submitForm(){
            console.log("调用提交");
            if (this.fogFrom.mid===0||this.fogFrom.level===3||this.fogFrom.date_temp===""){
                layer.msg('请将信息完整输入!', {
                    time: 2000
                });
                return false;
            }
            if ('http://nitcs.ahalk.cn/img/'+this.fogFrom.url===this.myurl[0].url){
                this.$http.post('/admin/FogLevelUpdate',this.fogFrom,{emulateJSON:true}).then(res => {
                    layer.msg('修改成功!', {
                        time: 2000
                    });
                    setTimeout(() => {
                        location.href = "/admin/fog.html";
                    }, 1000);
                });
                return false;
            }
            if (this.$refs.upload.uploadFiles.length===0){
                layer.msg('请将信息完整输入!', {
                    time: 2000
                });
                return false;
            }
            this.fogFrom.url=this.$refs.upload.uploadFiles[0].raw.name;
            this.$refs.upload.submit();
        },
        //图片
        handleRemove(file) {
            this.myurl[0].url="000000000";
            this.$refs.upload.clearFiles();
            $(".el-upload--picture-card").css("display","block");
            console.log(file);
        },
        handlePictureCardPreview(file) {
            this.dialogImageUrl = file.url;
            this.dialogVisible = true;
        },
        changelist(file){
            if (this.$refs.upload){
                $(".el-upload--picture-card").css("display","none");
            }
        },
        geturl(res){
            console.log(res);
            console.log(this.fogFrom.url);
            if (this.fogFrom.mid===0||this.fogFrom.url===""||this.fogFrom.level===3||this.fogFrom.date_temp===""){
                layer.msg('请将信息完整输入!', {
                    time: 2000
                });
                return false;
            }
            this.$http.post('/admin/FogLevelUpdate',this.fogFrom,{emulateJSON:true}).then(res => {
                layer.msg('修改成功!', {
                    time: 2000
                });
                setTimeout(() => {
                    location.href = "/admin/fog.html";
                }, 1000);
            });
        }
    }
})